class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}





public class project {
    public boolean stoneGameIX(int[] stones) {
        int count0=0;
        int count1=0;
        int count2=0;
        for(int stone:stones){
            int tmp=stone%3;
            if(tmp==0){
                count0++;
            }else if(tmp==1){
                count1++;
            }else{
                count2++;
            }
        }
        if(count0%2==0){
            return count1>0&&count2>0;
        }
        return count1-count2>2||count2-count1>2;
    }
















    public ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode prev=head;
        ListNode newHead=head.next;
        ListNode cur=newHead;
        while (cur!=null&&cur.next!=null){
            prev.next=cur.next;
            prev=prev.next;
            cur.next=prev.next;
            cur=cur.next;
        }
        prev.next=newHead;
        return head;
    }





















    public ListNode sortList(ListNode head) {
        return MySort(head);
    }
    public ListNode MySort(ListNode head){
        if(head==null||head.next==null){
            return head;
        }
        ListNode left=head;
        ListNode right=head.next;
        while (right!=null&&right.next!=null) {
            left = left.next;
            right = right.next.next;
        }
        ListNode newHead=left.next;
        left.next=null;
        return MySorts(MySort(head),MySort(newHead));
    }
    public ListNode MySorts(ListNode l,ListNode r){
        ListNode newHead=new ListNode(-1);
        ListNode cur=newHead;
        while (l!=null&&r!=null){
            if(l.val<r.val){
                cur.next=l;
                l=l.next;
            }else{
                cur.next=r;
                r=r.next;
            }
            cur=cur.next;
        }
        if(l!=null){
            cur.next=l;
        }
        if(r!=null){
            cur.next=r;
        }
        return newHead.next;
    }
}
